import 'dart:convert' show json;
import 'ModelBase.dart';

class User extends ModelBase {
  User({
    this.headImg,
    this.id,
    this.name,
    this.phone,
  });

  factory User.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : User(
          headImg: asT<String>(jsonRes['headImg']),
          id: asT<int>(jsonRes['id']),
          name: asT<String>(jsonRes['name']),
          phone: asT<String>(jsonRes['phone']),
        );

  String headImg;
  int id;
  String name;
  String phone;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'headImg': headImg,
        'id': id,
        'name': name,
        'phone': phone,
      };
  @override
  String toString() {
    return json.encode(this);
  }
}

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }

  return null;
}
